<template>
  <div class="register-page">
    <div class="register-container">
      <div class="register-box">
        <div class="register-header">
          <router-link to="/" class="logo">
            <img src="@/assets/headphone-logo.png" alt="Logo" />
          </router-link>
          <h2>创建账户</h2>
          <p>加入音悦耳机，畅享音乐世界</p>
        </div>

        <form @submit.prevent="handleSubmit" class="register-form">
          <div class="form-group">
            <label>
              <i class="fas fa-user"></i>
              <input
                type="text"
                v-model="form.username"
                placeholder="请输入用户名"
                required
              />
            </label>
          </div>

          <div class="form-group">
            <label>
              <i class="fas fa-lock"></i>
              <input
                :type="showPassword ? 'text' : 'password'"
                v-model="form.password"
                placeholder="请设置密码"
                required
              />
              <button
                type="button"
                class="toggle-password"
                @click="showPassword = !showPassword"
              >
                <i
                  :class="['fas', showPassword ? 'fa-eye-slash' : 'fa-eye']"
                ></i>
              </button>
            </label>
          </div>

          <div class="form-group">
            <label>
              <i class="fas fa-lock"></i>
              <input
                :type="showConfirmPassword ? 'text' : 'password'"
                v-model="form.confirmPassword"
                placeholder="请确认密码"
                required
              />
              <button
                type="button"
                class="toggle-password"
                @click="showConfirmPassword = !showConfirmPassword"
              >
                <i
                  :class="[
                    'fas',
                    showConfirmPassword ? 'fa-eye-slash' : 'fa-eye',
                  ]"
                ></i>
              </button>
            </label>
          </div>

          <div class="agreement">
            <label class="checkbox">
              <input type="checkbox" v-model="form.agreement" required />
              <span>我已阅读并同意</span>
            </label>
            <a href="#" class="terms">《用户协议》</a>和
            <a href="#" class="privacy">《隐私政策》</a>
          </div>

          <button type="submit" class="submit-btn" :disabled="loading">
            {{ loading ? "注册中..." : "立即注册" }}
          </button>

          <div class="divider">
            <span>其他注册方式</span>
          </div>

          <div class="social-login">
            <button type="button" class="social-btn wechat">
              <i class="fab fa-weixin"></i>
            </button>
            <button type="button" class="social-btn qq">
              <i class="fab fa-qq"></i>
            </button>
            <button type="button" class="social-btn weibo">
              <i class="fab fa-weibo"></i>
            </button>
          </div>
        </form>

        <div class="login-link">
          已有账号？<router-link to="/login">立即登录</router-link>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "RegisterView",
  data() {
    return {
      loading: false,
      showPassword: false,
      showConfirmPassword: false,
      form: {
        username: "",
        password: "",
        confirmPassword: "",
        agreement: false,
      },
    };
  },
  methods: {
    async handleSubmit() {
      // 表单验证
      if (
        !this.form.username ||
        !this.form.password ||
        !this.form.confirmPassword
      ) {
        alert("请填写完整信息");
        return;
      }

      if (this.form.password !== this.form.confirmPassword) {
        alert("两次输入的密码不一致");
        return;
      }

      this.loading = true;
      try {
        // 模拟注册API调用
        await new Promise((resolve) => setTimeout(resolve, 1000));
        alert("注册成功！");
        this.$router.push("/login");
      } catch (error) {
        alert("注册失败，请稍后再试");
        console.error("注册失败:", error);
      } finally {
        this.loading = false;
      }
    },
  },
};
</script>

<style scoped>
.register-page {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #fff6f6 0%, #ffe9e9 100%);
  padding: 40px 20px;
}

.register-container {
  background: white;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  width: 100%;
  max-width: 450px;
}

.register-box {
  padding: 40px;
}

.register-header {
  text-align: center;
  margin-bottom: 30px;
}

.register-header .logo img {
  width: 80px;
  margin-bottom: 15px;
}

.register-header h2 {
  font-size: 28px;
  color: #333;
  margin-bottom: 10px;
}

.register-header p {
  color: #666;
  font-size: 15px;
}

.form-group {
  margin-bottom: 20px;
  position: relative;
}

.form-group label {
  display: flex;
  align-items: center;
  border: 1px solid #ddd;
  border-radius: 5px;
  padding: 10px 15px;
  transition: all 0.3s ease;
}

.form-group label:focus-within {
  border-color: #ff6b6b;
  box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.2);
}

.form-group i {
  color: #999;
  margin-right: 10px;
}

.form-group input {
  border: none;
  outline: none;
  flex-grow: 1;
  font-size: 16px;
  padding: 5px 0;
}

/* Removed verification specific styles */

.toggle-password {
  background: none;
  border: none;
  cursor: pointer;
  color: #999;
  font-size: 16px;
  padding: 0;
}

.agreement {
  display: flex;
  align-items: center;
  font-size: 14px;
  color: #666;
  margin-bottom: 25px;
}

.agreement .checkbox {
  margin-right: 10px;
}

.agreement input[type="checkbox"] {
  margin-right: 5px;
  accent-color: #ff6b6b;
}

.agreement a {
  color: #ff6b6b;
  text-decoration: none;
}

.agreement a:hover {
  text-decoration: underline;
}

.submit-btn {
  width: 100%;
  padding: 15px;
  background: #ff6b6b;
  color: white;
  border: none;
  border-radius: 5px;
  font-size: 18px;
  cursor: pointer;
  transition: background 0.3s ease;
}

.submit-btn:hover {
  background: #ff5252;
}

.submit-btn:disabled {
  background: #cccccc;
  cursor: not-allowed;
}

.divider {
  text-align: center;
  margin: 30px 0;
  position: relative;
  color: #aaa;
}

.divider::before,
.divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: #eee;
}

.divider::before {
  left: 0;
}

.divider::after {
  right: 0;
}

.divider span {
  background: white;
  padding: 0 10px;
  z-index: 1;
  position: relative;
}

.social-login {
  display: flex;
  justify-content: center;
  gap: 15px;
  margin-bottom: 30px;
}

.social-btn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 24px;
  color: white;
  border: none;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.social-btn:hover {
  transform: translateY(-3px);
}

.social-btn.wechat {
  background: #4caf50;
}

.social-btn.qq {
  background: #2196f3;
}

.social-btn.weibo {
  background: #f44336;
}

.login-link {
  text-align: center;
  font-size: 15px;
  color: #666;
}

.login-link a {
  color: #ff6b6b;
  text-decoration: none;
}

.login-link a:hover {
  text-decoration: underline;
}
</style>
